<?php 

include '../utils/stock.php';
include '../utils/evaluator.php';
require('../utils/fpdf17/fpdf.php');
session_start() ;
?>
<html>
<head>
<style type="text/css">
body
{

font-family:"Calibri";}
}
</style>
</head>
<body>

<b>Book value (2 of 2)</b>
<br>

<br>

<?php
$years = $_POST["years"];
$bv2012 = $_POST["bv2012"];
$bv2011 = $_POST["bv2011"];
$bv2010 = $_POST["bv2010"];
$bv2009 = $_POST["bv2009"];
$bv2008 = $_POST["bv2008"];
$bv2007 = $_POST["bv2007"];
$bv2006 = $_POST["bv2006"];
$bv2005 = $_POST["bv2005"];
$bv2004 = $_POST["bv2004"];
$bv2003 = $_POST["bv2003"];
$growth2012 = ($bv2012 - $bv2011)/$bv2011;
$growth2011 = ($bv2011 - $bv2010)/$bv2010;
$growth2010 = ($bv2010 - $bv2009)/$bv2009;
$growth2009 = ($bv2009 - $bv2008)/$bv2008;
$growth2008 = ($bv2008 - $bv2007)/$bv2007;
$growth2007 = ($bv2007 - $bv2006)/$bv2006;
$growth2006 = ($bv2006 - $bv2005)/$bv2005;
$growth2005 = ($bv2005 - $bv2004)/$bv2004;
$growth2004 = ($bv2004 - $bv2003)/$bv2003;

$growth = array($growth2012,$growth2011, $growth2010, $growth2009, $growth2008, $growth2007,$growth2006,$growth2005,$growth2004);

echo "<table border=1>";
echo "<tr>";
echo "<td><b>Year</b></td>";
echo "<td><b>Bookvalue</b></td>";
echo "<td><b>Bookvalue Growth</b></td>";
echo "</tr>";


echo "<tr>";
echo "<td>2012</td>";
echo "<td>".$bv2012."</td>";
echo "<td>".$growth2012."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>2011</td>";
echo "<td>".$bv2011."</td>";
echo "<td>".$growth2011."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>2010</td>";
echo "<td>".$bv2010."</td>";
echo "<td>".$growth2010."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>2009</td>";
echo "<td>".$bv2009."</td>";
echo "<td>".$growth2009."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>2008</td>";
echo "<td>".$bv2008."</td>";
echo "<td>".$growth2008."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>2007</td>";
echo "<td>".$bv2007."</td>";
echo "<td>".$growth2007."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>2006</td>";
echo "<td>".$bv2006."</td>";
echo "<td>".$growth2006."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>2005</td>";
echo "<td>".$bv2005."</td>";
echo "<td>".$growth2005."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>2004</td>";
echo "<td>".$bv2004."</td>";
echo "<td>".$growth2004."</td>";
echo "</tr>";


echo "</table>";

for ($i = 0; $i < $years - 1; $i++) {
    $sum += $growth[$i];
}
$averagegrowth = $sum / ($years -1);
echo "<br>";
echo "<b>Present Book Value: </b>";
echo $bv2012;
echo "<br>";
echo "<b>Average growth ".$years." year(s): </b>";
echo $averagegrowth;
echo "<br>";
echo "<b>Future Book Value in 10 year(s): </b>";
$fbv = $bv2012*pow((1+$averagegrowth),10);
echo $fbv;
echo "<br>";


echo "<br>";
echo "<br>";
echo "Proceed if these numbers are correct, otherwise go back.";

$evaluator = $_SESSION['evaluator'];
$evaluator->bookvalue2012 = $bv2012;
$evaluator->average_growth = $averagegrowth;
$evaluator->nb_years_bookvalue = $years;
$evaluator->future_bookvalue = fbv;
$evaluator->bookvalue2012 = $_POST["bv2012"];
$evaluator->bookvalue2011 = $_POST["bv2011"];
$evaluator->bookvalue2010 = $_POST["bv2010"];
$evaluator->bookvalue2009 = $_POST["bv2009"];
$evaluator->bookvalue2008 = $_POST["bv2008"];
$evaluator->bookvalue2007 = $_POST["bv2007"];
$evaluator->bookvalue2006 = $_POST["bv2006"];
$evaluator->bookvalue2005 = $_POST["bv2005"];
$evaluator->bookvalue2004 = $_POST["bv2004"];
$evaluator->bookvalue2003 = $_POST["bv2003"];

$evaluator->bvg2012 = ($bv2012 - $bv2011)/$bv2011;
$evaluator->bvg2011 = ($bv2011 - $bv2010)/$bv2010;
$evaluator->bvg2010 = ($bv2010 - $bv2009)/$bv2009;
$evaluator->bvg2009 = ($bv2009 - $bv2008)/$bv2008;
$evaluator->bvg2008 = ($bv2008 - $bv2007)/$bv2007;
$evaluator->bvg2007 = ($bv2007 - $bv2006)/$bv2006;
$evaluator->bvg2006 = ($bv2006 - $bv2005)/$bv2005;
$evaluator->bvg2005 = ($bv2005 - $bv2004)/$bv2004;
$evaluator->bvg2004 = ($bv2004 - $bv2003)/$bv2003;

$_SESSION['evaluator'] = $evaluator;


function addColor($number, $reference){
	if($number >= $reference) 
	{
		$res = "<b><font color='green'>". $number . "</font></b>";
	}
	else 
	{
		$res = "<font color='red'>". $number . "</font>";
	}
	
	return $res;
}

?>


<br />
<button type="button" onclick="location.href='step3.php'">Back</button>
<button type="button" onclick="location.href='step3c.php'">Next</button>



</body>
</html> 